package com.jyc.service;

import com.jyc.entity.zuche.Car;
import com.jyc.entity.zuche.Zuche;
import com.jyc.entity.zuche.Zuchedidian;
import com.jyc.mapper.zuche.CarMapper;
import com.jyc.mapper.zuche.ZucheMapper;
import com.jyc.mapper.zuche.ZuchedidianMapper;
import com.jyc.util.HttpResult;
import com.jyc.vo.zuche.CarVO;
import com.jyc.vo.zuche.ZucheChartVO;
import com.jyc.vo.zuche.ZucheInfoVO;
import com.jyc.vo.zuche.ZuchedidianVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class ZucheService {
    @Autowired(required = false)
    private CarMapper carMapper;
    @Autowired(required = false)
    private ZuchedidianMapper zuchedidianMapper;
    @Autowired(required = false)
    private ZucheMapper zucheMapper;

    public List<ZucheInfoVO> getItemList() {
        List<ZucheInfoVO> zucheInfoVOS = new ArrayList<>();
        List<Zuche> zuches = zucheMapper.selectByExample(null);
        for (Zuche zuch : zuches) {
            Integer carid = zuch.getCarid();
            Integer zhucedidianid = zuch.getZhucedidianid();
            Car car = carMapper.selectByPrimaryKey(carid);
            CarVO carVO = new CarVO();
            BeanUtils.copyProperties(car,carVO);
            Zuchedidian zuchedidian = zuchedidianMapper.selectByPrimaryKey(zhucedidianid);
            ZuchedidianVO zuchedidianVO = new ZuchedidianVO();
            BeanUtils.copyProperties(zuchedidian,zuchedidianVO);
            ZucheInfoVO zucheInfoVO = new ZucheInfoVO();
            zucheInfoVO.setZucheInfo(zuch);
            zucheInfoVO.setCarInfo(carVO);
            zucheInfoVO.setZuchedidianInfo(zuchedidianVO);
            zucheInfoVOS.add(zucheInfoVO);
        }
        return zucheInfoVOS;
    }

    public List<List> show3D() {
        List<ZucheChartVO> zucheChartVOS= zucheMapper.show3D();
        List<List> chartData = new ArrayList<>();
        List first = new ArrayList();
        first.add("租赁地点");
        first.add("汽车名称");
        first.add("价格");
        first.add("车牌号");
        chartData.add(first);
        for (ZucheChartVO zucheChartVO : zucheChartVOS) {
            List tempList= new ArrayList();
            tempList.add(zucheChartVO.getPlacewhere());
            tempList.add(zucheChartVO.getCname() + "("+zucheChartVO.getCarcolor()+")");
            tempList.add(zucheChartVO.getPrice());
            tempList.add(zucheChartVO.getCarnumber().toString());
            chartData.add(tempList);
        }
        return chartData;
    }

    public List<ZucheChartVO> showPie() {
        return zucheMapper.showPie();
    }

    public List<ZucheChartVO> showPillar() {
        return zucheMapper.showPillar();
    }

    public List<ZucheChartVO> showLine() {
        return zucheMapper.showLine();
    }
}
